package com.quickstart.springboot.actuator.controller;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
/**
 * <p>描述: [功能描述] </p >
 *
 * @author yangzl
 * @version v1.0
 * @date 2020/9/9 00:11
 */
@Component
public class DownstreamServiceHealthIndicator implements ReactiveHealthIndicator {

  @Override
  public Mono<Health> health() {
    return checkDownstreamServiceHealth().onErrorResume(
        ex -> Mono.just(new Health.Builder().down(ex).build())
    );
  }

  private Mono<Health> checkDownstreamServiceHealth() {
    // we could use WebClient to check health reactively
    return Mono.just(new Health.Builder().up().build());
  }
}
